
/**
 *
 * @param <E>
 * @author David Coronado
 */
public class QueueArrayImplementation <E> extends BankQueueImplementation <E> {

    private E[] elements = (E[]) new Object[10];
    int nelements;

    /**
     * initialize the array in null and sets the number of elements to 0
     */
    public QueueArrayImplementation(){
        for(int i=0 ; i<10 ; i++ ){
            elements[i] = null;
        }
        nelements = 0;
    }
    
    /**
     *
     * @param Element to be added to the queue
     * @throws FullQueueException
     */
    @Override
    public void add(E Element) throws FullQueueException {
        if(nelements == 10){
            throw new FullQueueException();
        }
        
        elements[nelements] = Element;
        this.nelements++;
    }

    /**
     *
     * @return element removed from the queue
     * @throws EmptyQueueException
     */
    @Override
    public E remove() throws EmptyQueueException {
        if(elements[0] == null){
            throw new EmptyQueueException();
        }
        
        
        E element = this.elements[0];
        for(int x=0; x<9 ; x++){
            this.elements[x] = this.elements[x+1];
        }
        nelements--;
        return element;
    }

    /**
     *
     * @return a glance at the first element of the queue
     * @throws EmptyQueueException
     */
    @Override
    public E peek() throws EmptyQueueException {
        if(elements[0] == null){
            throw new EmptyQueueException();
        }
        
        return elements[0];
    }

    /**
         *
         * @return the size of the queue
         */
        public int size()
	{
		return nelements;
	}
}
